/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MyListRendererJCheckBox.java
 *
 * Copyright 2011 Universidad Francisco de Paula Santander (UFPS).
 * Todos los Derechos Reservados.
 * Creado el 3/03/2011, 04:34:40 PM
 */

package com.ufps.cuatro.util.render;

import java.awt.Color;
import java.awt.Component;
import java.io.Serializable;

import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.ufps.cuatro.util.Utileria;
import com.ufps.cuatro.util.model.MyCheckItemPropertiesClass;

/**
 * <i><b>MyListRendererJCheckBox:</b></i>@DefinicionClase
 * @author Carlos A. Torres C. - Dolly E. Guerrero. <https://code.google.com/p/tesis4dor/>
 * @version 1.0 3/03/2011
 * @see JCheckBox
 * @see ListCellRenderer
 * @see Serializable
 */
public class MyListRendererJCheckBox extends JCheckBox implements ListCellRenderer, Serializable{

    
    private static final long serialVersionUID = 8184740772734518579L;
    
    /**
     * @DefinicionMetodo
     * @param modo @DefinicionParametro
     */
    public MyListRendererJCheckBox() {        
    }

    private JCheckBox setIcono(String key, String info, boolean seleccionado, boolean estado){
        ImageIcon icono = Utileria.leerRecursoImagen(key, 16);
        JLabel labelIcono = new JLabel(icono);
        
        JCheckBox objItem = new JCheckBox(info, /*labelIcono.getIcon(),*/ estado);
        //this.setIcon(labelIcono.getIcon());
        //this.setText(info);
        
        if(seleccionado){
            //this.setOpaque(true);
            //this.setForeground(new Color(255,255,255));
            //this.setBackground(new Color(33,66,99));
            objItem.setOpaque(true);
            objItem.setForeground(new Color(255,255,255));
            objItem.setBackground(new Color(33,66,99));
        }
        else{
            //this.setForeground(new Color(0,0,0));
            //this.setOpaque(false);
            objItem.setForeground(new Color(0,0,0));
            objItem.setOpaque(false);
            
        }
        //this.setSelected(estado);
        objItem.setSelected(estado);
        
        return objItem;
    }


    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {        
        if(value instanceof MyCheckItemPropertiesClass){
            MyCheckItemPropertiesClass objItem = (MyCheckItemPropertiesClass) value;
            if(objItem.getObjField() != null){                
                return this.setIcono(Utileria.ICONO_ATRIBUTO, objItem.getObjField().getName(), isSelected, objItem.isSelected());
            }
            else if(objItem.getObjMethod() != null){                
                return this.setIcono(Utileria.ICONO_METODO, objItem.getObjMethod().getName(), isSelected, objItem.isSelected());
            }
        }       
        return null;
    }


}

